// index.js
// 获取应用实例
const app = getApp()

Page({
  data: {
    catelist:["男装","女装","零食","家电","床上用品","家具"],
    bannerlist: [{
      url:"../../images/banner1.jpg"
    },{
      url:"../../images/banner2.jpg"
    },{
      url:"../../images/banner3.jpg"
    }],
    latitude:"",
    longitude:""
  },
 
  onLoad() {
 
  },
  saveUserInfo:function(){
var data = {"name":"王瑜","student_id":"201965110457"}
wx.setStorageSync("userinfo",data)
//异步缓存
wx.setStorage({
  key:"studentinfo",
  data: {"sex":"女","age":11}
 
})
  },
  getUserInfo:function(){
    //同步缓存数据
   var studentinfo =  wx.setStorageSync('studentinfo');
   console.log(studentinfo);
   //异步获取数据
   wx.setStorage({
     key: "userinfo",
     success(res){
       console.log(res);
     }
   })
   wx.getStorageInfo({
   
  
     success:(option) =>{
       console.log(option)
     },
    })

  },
  removeUserInfo:function(){
//异步移除
wx.removeStorage({
  key: 'userinfo',
})
wx.removeStorageSync('studentinfo')
  },
  getLocal:function(){
    var then = this;
    wx.getLocation({
    success(res){
     then.setData({
       latitude:res.latitude,
       longitude:res.longitude
     })
    }
    })

  },
  openMap:function(){
    var then = this;
    wx.openLocation({
      latitude: then.data.latitude,
      longitude: then.data.longitude,
      name:"湖南开放大学终教楼1104",
      address:"湖南省长沙市天心区青园路168号1104"
    })
   
  },
  selectLocal:function(){
    var then = this;
    wx.chooseLocation({
      latitude: then.data.latitude,
      longitude: then.data.longitude
    })
   
  },
  call:function(){
    wx.makePhoneCall({
      phoneNumber: '130',
    })
  },
  scanCode:function(){
    wx.scanCode({
      onlyFromCamera: true,
      success(res){
console.log(res)
      }
    })
  },
  selectImage:function(){
    wx.chooseImage({
      count: 1,
      sourceType:['camera'],
      success(res){
        console.log(res);
        wx.previewImage({
          urls: [res.tempFilePaths[0]],
        })
        wx.getImageInfo({
          src: res.tempFilePaths[0],
          success(res){
            console.log(res)
          }
        })
      }
    })
  },
  saveImage:function(){
    wx.saveImageToPhotosAlbum({
      filePath: "http://tmp/kr0bgy7WLfmP822fa1bae76557fab9565235af90fe4a.png",
    })
  }
})

